home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / winlib1.zip / MENUDEMO.C < prev    next >
Text File  |  1991-01-16  |  15KB  |  462 lines

  1. /* Date 1-15-91 */
  2.  
  3. /*********************************************************************
  4.  * This is the demonstration program of the menu functions available *
  5.  * with The C Window Library.                                        *
  6.  *                                                                   *
  7.  * For Turbo C version 1.5 and above,  compile using the following:  *
  8.  *     tcc -mm -Ixxx menudemo.c tcwinm.lib                           *
  9.  * where xxx is the directory of The C Window Library header files.  *
  10.  *                                                                   *
  11.  * For Microsoft C users Version 5.1 and above:                      *
  12.  *     cl -AM -DMSC -Ixxx menudemo /link /SE:1000 mswinm.lib         *
  13.  * (use "qcl" instead of "cl" if using Quick C)                      *
  14.  * where xxx is the directory of The C Window Library header files.  *
  15.  *                                                                   *
  16.  * For Zortech C++ Version 2.0 and above:                            *
  17.  *     ztc -mm -p -b -Ixxx menudemo.c zcwinm.lib                     *
  18.  * where xxx is the directory of The C Window Library header files.  *
  19.  *                                                                   *
  20.  * For Power C Version 2.0 and above:                                *
  21.  *     pc -DPOWERC -mm -c -ixxx menudemo.c                           *
  22.  *     pcl [10k,30k,300k] menudemo,pcwinm                            *
  23.  * where xxx is the directory of The C Window Library header files.  *
  24.  *********************************************************************/
  25.  
  26.  
  27. #include <menu.h>
  28.  
  29. /* define colors */
  30.  
  31. #define YELLOWONRED    CREATE_VIDEO_ATTRIBUTE(red,yellow)
  32. #define WHITEONBLUE    CREATE_VIDEO_ATTRIBUTE(blue,white)
  33. #define BLUEONWHITE    CREATE_VIDEO_ATTRIBUTE(white,blue)
  34. #define BLACKONCYAN    CREATE_VIDEO_ATTRIBUTE(cyan,black)
  35. #define NORM           CREATE_VIDEO_ATTRIBUTE(black,white)
  36. #define BLACKONWHITE   CREATE_VIDEO_ATTRIBUTE(white,black)
  37.  
  38. WPOINTER help,pw;
  39. VBLOCKPTR v;
  40.  
  41.  
  42. int rt1();      /* Routine that is called when popup option is chosen */
  43. int rt2();      /* Routine that is called when bar option is chosen */
  44. int rt3();      /* Routine that is called when pulldown option is chosen */
  45. int beep_it();  /* Routine that is called when undefined key is pressed */
  46. void bar_demo();      /* Routine to do bar menu demo */
  47. void popup_demo();    /* Routine to do popup demo */
  48. void pulldown_demo(); /* Routine to do pulldown menu demo */
  49.  
  50.  
  51.  
  52. /*****************************
  53.  * Define popup menu entries *
  54.  ****************************/
  55.  
  56. POPUP_MENU_ENTRY menu_items1[] = {
  57.                                   " Load      F3", /* option name */
  58.                                     1,             /* row number */
  59.                                    'L',            /* hotkey */
  60.                                     F3,            /* secondary hotkey */
  61.                                     rt1,      /* function to call if chosen */
  62.  
  63.                                  /* now do rest of the popup entries */
  64.                                   " Pick  Alt-F3",2, 'P',ALTF3,rt1,
  65.                                   " New"         ,3, 'N',0,rt1,
  66.                                   " Save      F2",4, 'S',F2,rt1,
  67.                                   " Write to    ",5, 'W',0,rt1,
  68.                                   " Directory   ",6, 'D',0,rt1,
  69.                                   " Change Dir"  ,7, 'C',0,rt1,
  70.                                   " OS shell"    ,8, 'O',0,rt1,
  71.                                   " Quit  Alt-X"  ,9,'Q',ALTX,rt1,
  72.  
  73.  
  74.                                  /* Terminate with a NULL and 0 */
  75.  
  76.                                     CWL_NULL,0};
  77.  
  78.  
  79.  
  80. POPUP_MENU_ENTRY menu_items3[] = {
  81.                       " Run             Ctrl-F9 ",1,'R',CTRLF9,rt3,
  82.                       " Program reset   Ctrl-F2 ",2,'P',CTRLF2,rt3,
  83.                       " Go to Cursor         F4 ",3,'G',F4,rt3,
  84.                       " Trace into           F7 ",4,'T',F7,rt3,
  85.                       " Step over            F8 ",5,'S',F8,rt3,
  86.                       " User screen      Alt-F5 ",6,'U',ALTF5,rt3,
  87.                         CWL_NULL,0};
  88.  
  89.  
  90. POPUP_MENU_ENTRY menu_items4[] = {
  91.         " Compile to OBJ                   ",1,'C',0,rt3,
  92.         " Make EXE file                    ",2,'M',0,rt3,
  93.         " Link EXE file                    ",3,'L',0,rt3,
  94.         " Build all                        ",4,'B',0,rt3,
  95.         " Primary C file:                  ",5,'P',0,rt3,
  96.         " Get info                         ",6,'G',0,rt3,
  97.           CWL_NULL,0};
  98.  
  99.  
  100. POPUP_MENU_ENTRY menu_items5[] = {
  101.         " Project Name                     ",1,'P',0,rt3,
  102.         " Break make on                    ",2,'B',0,rt3,
  103.         " Auto dependencies                ",3,'A',0,rt3,
  104.         " Clear project                    ",4,'C',0,rt3,
  105.         " Remove messages                  ",5,'R',0,rt3,
  106.           CWL_NULL,0};
  107.  
  108.  
  109. POPUP_MENU_ENTRY menu_items6[] = {
  110.         " Compiler          ",1,'C',0,rt3,
  111.         " Linker            ",2,'L',0,rt3,
  112.         " Environment       ",3,'E',0,rt3,
  113.         " Directories       ",4,'D',0,rt3,
  114.         " Arguments         ",5,'A',0,rt3,
  115.         " Save Options      ",6,'S',0,rt3,
  116.         " Retrieve options  ",7,'R',0,rt3,
  117.           CWL_NULL,0};
  118.  
  119.  
  120. POPUP_MENU_ENTRY menu_items7[] = {
  121.         " Evaluate    Ctrl-F4           ",1,'E',CTRLF4,rt3,
  122.         " Call Stack  Ctrl-F3           ",2,'C',CTRLF3,rt3,
  123.         " Find Function                 ",3,'F',0,rt3,
  124.         " Refresh display               ",4,'R',0,rt3,
  125.         " Display swapping     Smart    ",5,'D',0,rt3,
  126.         " Source debugging              ",6,'S',0,rt3,
  127.           CWL_NULL,0};
  128.  
  129.  
  130. POPUP_MENU_ENTRY menu_items8[] = {
  131.         " Add watch           Ctrl-F7 ",1,'A',CTRLF7,rt3,
  132.         " Delete watch                ",2,'D',0,rt3,
  133.         " Edit Watch                  ",3,'E',0,rt3,
  134.         " Remove all watches          ",4,'R',0,rt3,
  135.         " Toggle breakpoint   Ctrl-F8 ",6,'T',CTRLF8,rt3,
  136.         " Clear all breakpoints       ",7,'C',0,rt3,
  137.         " View next breakpoint        ",8,'V',0,rt3,
  138.           CWL_NULL,0};
  139.  
  140.  
  141.  
  142.  
  143.  
  144. /**********************
  145.  * Define Bar entries *
  146.  *********************/
  147.  
  148. BAR_MENU_ENTRY bar_items[] = {
  149.       "File",       1,4, 'F',0,rt2,
  150.       "Edit",       1,10,'E',0,rt2,
  151.       "Run",        1,17,'R',0,rt2,
  152.       "Compile",    1,23,'C',0,rt2,
  153.       "Project",    1,33,'P',0,rt2,
  154.       "Options",    1,43,'O',0,rt2,
  155.       "Debug",      1,53,'D',0,rt2,
  156.       "Break/watch",1,61,'B',0,rt2,
  157.                   CWL_NULL};
  158.  
  159.  
  160. /* Define array of POPUP_MENU_ENTRY's used for pulldown menu */
  161. /* This array is used for convenience when initializing all of the
  162.  * POPUP_MENU_PTR's               */
  163.  
  164. POPUP_MENU_ENTRY  *pentry[] = {menu_items1, POPUP_ENTRY_NULL, menu_items3,
  165.                                menu_items4, menu_items5, menu_items6,
  166.                                menu_items7, menu_items8};
  167.  
  168.  
  169. unsigned menu_colors[5];    /* Menu colors */
  170. BAR_MENU_PTR bar;           /* Pointer to bar menu */
  171. POPUP_MENU_PTR popups[8];   /* Array of pointers to pop-up menus */
  172. PULLDOWN_MENU_PTR pull;     /* Pointer to pulldown menu */
  173.  
  174. WPOINTER my_open();         /* Pointer to custom bar window open function */
  175. int popuprank[] = {1,1,1,1,1,1,1,1};  /* Ranks of pop-up windows */
  176. unsigned popupstart[] = {1,1,1,1,1,1,1,1}; /* Starting option for each pop-up
  177.                                               menu */
  178. int height[] = {9,0,6,6,5,7,6,8};     /* height of each window */
  179.  
  180.  
  181.  
  182. char *line =
  183.         "─────────────────────────────"; /* Horizontal line */
  184.  
  185.  
  186. void main()
  187. {
  188.   int i,d;
  189.  
  190.   /* Get Choice of which screen method to use */
  191.   printf("\nPlease enter: '0' for Direct Screen Writes\n"
  192.      "              '1' for Direct Screen Writes with snow checking\n"
  193.      "              '2' for BIOS Screen updates: ");
  194.   scanf("%d",&d);
  195.   WindowInitializeSystem();
  196.   CHECK_SNOW = d;
  197.   SCREEN_WRITE_METHOD = (d == 2)?BIOS:DMA;
  198.  
  199.   /* Initialize The C Window Library */
  200.  
  201.   /* Save Initial Screen as a VBLOCK */
  202.   v = VideoSave(1,1,num_screen_rows,num_screen_cols);
  203.   ClearScreen(NORM);
  204.  
  205.   /* Save Base Screen as a window */
  206.   WindowSaveInitial(active_video_page);
  207.  
  208.   /* Initialize Info Window */
  209.   pw = WindowInitialize(BORDER,19,10,50,4,CREATE_VIDEO_ATTRIBUTE(black,white),
  210.               CREATE_VIDEO_ATTRIBUTE(black,white), SINGLEBOX);
  211.  
  212.   /* Open Info Window */
  213.   WindowOpen(pw);
  214.  
  215.   /* Initialize And Open Help Window */
  216.   help = WindowInitialize(NOBORDER,25,1,80,1,BLACKONWHITE,BLACKONWHITE,0);
  217.   WindowOpen(help);
  218.  
  219.   /* Write Help Info to help window */
  220.   WindowWriteCenterString(help,
  221.   "Press \030 or \031 to move bar,   ─┘ or hotkey to accept,   ESC to exit",1);
  222.  
  223.  /* define colors */
  224.   menu_colors[ENTRYCOLOR] =
  225.   menu_colors[UNAVAILCOLOR] =
  226.   menu_colors[BORDERCOLOR] = CREATE_VIDEO_ATTRIBUTE(white,black);
  227.  
  228.   menu_colors[HOTKEYCOLOR] =
  229.   menu_colors[HIGHLIGHTCOLOR] = CREATE_VIDEO_ATTRIBUTE(black,white);
  230.  
  231.   /* Call Popup Demo */
  232.   popup_demo();
  233.  
  234.   /* Call Bar Demo */
  235.   bar_demo();
  236.  
  237.   /* Call Pulldown Demo */
  238.   pulldown_demo();
  239.  
  240.   /* Restore Initial Screen */
  241.   VideoRestore(v);
  242. }
  243.  
  244.  
  245. void popup_demo()
  246. {
  247.   POPUP_MENU_PTR p;
  248.  
  249.  /* create a POPUP_MENU_PTR */
  250.   p = PopupCreateMenu(menu_items1,menu_colors, 1,31,9,WNULLFN,VWNULLFN);
  251.  
  252.  /* Set Wrap and Remain on screen options */
  253.   PopupSetOptions(p,POPUPWRAP | POPUPSTATIC,1);
  254.  
  255.  /* Define routine to do when undefined key is pressed */
  256.   popup_undef_key = beep_it;
  257.  
  258.  /* Display the help window */
  259.   WindowDisplay(help,1,NOEFFECT);
  260.  
  261.  /* Call Selection Function */
  262.   PopupSelectMenu(p,  /* POPUP_MENU_PTR */
  263.                    1,  /* rank of pop-up window */
  264.                    1   /* menu option to start on */
  265.                   );
  266.  
  267.  /* Dispose of popup menu */
  268.   PopupMenuFree(p);
  269. }
  270.  
  271.  
  272.  
  273.  /* Routine that is called when popup function is invoked */
  274.  
  275. int rt1(POPUP_MENU_PTR p, int which)
  276. {
  277.   WindowClear(pw);
  278.  
  279.  /* Display the entry name that was chosen */
  280.   WindowPrintf(pw,"You have selected %s",POPUP_ENTRY_STRING(p,which));
  281.  
  282.   WindowWriteCenterString(pw,"Press a key to continue",4);
  283.  
  284.  /* Display the window with all the info */
  285.   WindowDisplay(pw,1,NOEFFECT);
  286.   GET_KEY();
  287.  
  288.  /* Hide the info window */
  289.   WindowHide(pw,NOEFFECT);
  290.  
  291.  /* If "Quit   Alt-X" was selected, then get out of popup menu */
  292.   if (which == 9)
  293.     return POPUP_EXIT;
  294.  
  295.  /* Keep getting popup selections */
  296.   else
  297.   return POPUP_CONTINUE;
  298. }
  299.  
  300.  
  301. void bar_demo()
  302. {
  303.   BAR_MENU_PTR b;
  304.  
  305.  /* Create Bar Menu */
  306.   b = BarCreateMenu(bar_items, menu_colors,1,1,WNULLFN);
  307.  
  308.  /* Set wrap and remain on screen options */
  309.   BarSetOptions(b,BARWRAP | BARSTATIC ,1);
  310.  
  311.  /* Assign routine to call when undefined key is pressed */
  312.   bar_undef_key = beep_it;
  313.  
  314.  /* Clear and rewrite help info in help window */
  315.   WindowClear(help);
  316.   WindowWriteCenterString(help,
  317.   "Press \032 or \033 to move bar,   ─┘ or hotkey to accept,   ESC to exit",1);
  318.  
  319.  /* Call Bar Selection function */
  320.   BarSelectMenu(b,        /* BAR_MENU_PTR */
  321.                 1,        /* Rank of bar window */
  322.                 1);       /* Starting Entry */
  323.  
  324.  /* Dispose of Bar Menu */
  325.   BarMenuFree(b);
  326. }
  327.  
  328.  
  329. int rt2(BAR_MENU_PTR b, int which)
  330. {
  331.   WindowClear(pw);
  332.  
  333.   /* Display the entry name that was chosen */
  334.   WindowPrintf(pw,"You have selected %s",BAR_ENTRY_STRING(b,which));
  335.   WindowWriteCenterString(pw,"Press a key to continue",4);
  336.   WindowDisplay(pw,1,NOEFFECT);
  337.   GET_KEY();
  338.  
  339.   /* Hide window */
  340.   WindowHide(pw,NOEFFECT);
  341.  
  342.   /* Keep getting selections */
  343.   return BAR_CONTINUE;
  344. }
  345.  
  346.  
  347.  
  348. void pulldown_demo()
  349. {
  350.   int i;
  351.  
  352.  
  353.  /* Rewrite help window */
  354.   WindowClear(help);
  355.   WindowWriteCenterString(help,
  356.   "Press \030 \031 \032 \033 to move bar,   ─┘ or hotkey to accept,   ESC (twice) to exit",1);
  357.  
  358.  /* Reassign functions of the bar menu entry */
  359.   for (i=0;i<=7;i++)
  360.     bar_items[i].func = NULLFN;
  361.  
  362.  /* Make special case for "Edit" entry */
  363.   bar_items[1].func = rt3;
  364.  
  365.  /* Reassign function for the menu_items1 POPUP_MENU_ENTRY */
  366.   for (i=0;i<=8;i++)
  367.     menu_items1[i].func = rt3;
  368.  
  369.  /* Create a BAR_MENU_PTR */
  370.   bar = BarCreateMenu(bar_items,  /* Array of BAR_MENU_ENTRY's   */
  371.                       menu_colors,/* Pointer to menu colors      */
  372.                       6,          /* Row to open bar menu window */
  373.                       1,          /* Column to open bar menu window */
  374.                       my_open);   /* Customized window open function */
  375.  
  376.  /* Now set bar options  */
  377.   BarSetOptions(bar,BARWRAP | BARSTATIC,1);   /* Wrap highlight bar */
  378.  
  379.  /* Now loop to create all pop-up menus
  380.     Be careful and asign NULL to the second pop-up menu */
  381.  
  382.   for (i=0; i<8; i++)       /* Loop for all pop-up menus */
  383.   {
  384.     if (pentry[i] != POPUP_ENTRY_NULL)  /* Skip over NULL pop-up window */
  385.     {
  386.       popups[i] =
  387.       PopupCreateMenu(pentry[i],   /* Array of POPUP_MENU_ENTRY's */
  388.                       menu_colors, /* Array of menu colors,        */
  389.  
  390.                         /* The next two arguments will later be ignored */
  391.                         1,           /* Row to open pop-up window on */
  392.                         1,           /* Column to open pop-up */
  393.  
  394.                         height[i], /* height of the pop-up window   */
  395.                                          /* No custom window open
  396.                                             functions */
  397.                         WNULLFN,
  398.                         VWNULLFN);
  399.  
  400.  
  401.       /* Now set the pop-up menu options */
  402.       PopupSetOptions(popups[i],POPUPWRAP | POPUPSTATIC,1);   /* Wrap the window */
  403.     }
  404.     else
  405.       popups[i] = POPUP_NULL_PTR;   /* Assign NULL to second pop-up window */
  406.   }  /* end for (i=0 ... */
  407.   VirtualWriteString(POPUP_VIRTUAL_WINDOW(popups[7]),line,5,1);/* Draw horizontal line in virtual
  408.                                                     popup window popups[7] */
  409.  
  410.   PopupMakeEntryUnavailable(popups[6],2);   /* hide 2nd and 3rd entries in */
  411.   PopupMakeEntryUnavailable(popups[6],3);   /* popups[6]  */
  412.  
  413.  /* Now put bar and array of POPUP_MENU_PTR's together by calling
  414.     PulldownCreateMenu()    */
  415.   pull = PulldownCreateMenu(popups,bar,1);
  416.  
  417.  /* Call Pulldown Select function */
  418.   PulldownSelectMenu(pull,1,1,popuprank,popupstart,1);
  419.  
  420.  /* Dispose of pulldown menu and all other menus used to build it */
  421.   PulldownMenuFreeAll(pull);
  422. }
  423.  
  424.  
  425. int rt3(PULLDOWN_MENU_PTR p, BAR_MENU_PTR b, POPUP_MENU_PTR pop,
  426.         int hs, int vs)
  427. {
  428.   int ch;
  429.   WindowClear(pw);
  430.   WindowPrintf(pw,"You have selected bar option %s\n",
  431.                    BAR_ENTRY_STRING(b,hs));
  432.   if (pop != (POPUP_MENU_PTR)0)
  433.     WindowPrintf(pw,"Popup entry %s",POPUP_ENTRY_STRING(pop,vs));
  434.   WindowWriteCenterString(pw,"Press a key to continue...",3);
  435.   WindowDisplay(pw,1,NOEFFECT);
  436.   ch = GET_KEY();
  437.   WindowHide(pw,NOEFFECT);
  438.   if (ch == ESC)
  439.     return PULLDOWN_POPUP_EXIT;
  440.   return PULLDOWN_CONTINUE;
  441. }
  442.  
  443.  
  444.  
  445. WPOINTER my_open()          /* Custom window open function for bar menu */
  446. {
  447.   WPOINTER w;
  448.   w = WindowInitialize(NOBORDER,1,1,80,1,BLACKONWHITE,BLACKONWHITE,"");
  449.   WindowOpen(w);
  450.   return w;
  451. }
  452.  
  453.  
  454. int beep_it()
  455. {
  456.   MakeSound(100,200);         /* Produce error tone */
  457.   return DONT_PROCESS;
  458. }
  459.  
  460.  
  461.  
  462.